<template>
  <div class = "userinfo_wrapper">
    <div class="avatar_wrapper"><el-avatar icon="el-icon-user-solid"></el-avatar></div>
    <div class="username_wrapper">{{username}}</div>
  </div>
</template>

<script>
  import {postRequest, getRequest} from "../../utils/api";
  import {strsutils} from "../../utils/strutils";
  let baseurl = strsutils.baseurl
  export default {
      // props:['username'],
      name: "Usertop",
      data(){
        return {
          username: 'libai-'
        }
      },
      mounted() {
        this.getUserInfo()
      },
      methods: {
        getUserInfo(){
          let _this = this
          let userid = window.localStorage.getItem('userid')
          getRequest(baseurl+'/getUserInfo/'+userid, '').then(function (res) {
            console.debug(res)
            console.debug("获取用户信息成功："+res.data.username)
            _this.username = res.data.username
          }).catch(function (err) {
            console.debug("获取用户信息失败"+err)
            _this.$message.error('获取用户信息失败')
          })
        }
      }
    }
</script>

<style scoped>

</style>
